// pages/index/professiondetail/professiondetail.js

import {
    GetMajorDtl, // 专业详情
    GetCollect, // 收藏
    GetCancelCollect, // 取消收藏
} from '../../../api/index'

import Toast from '../../../miniprogram_npm/@vant/weapp/toast/toast'

Page({

    /**
     * 页面的初始数据
     */
    data: {
        model: {},
        educational: '', // 学历 1本科 2专科
        introList: [{
                title: "授予学位",
                detial: ''
            },
            {
                title: "专业排名",
                detial: ''
            },
            {
                title: "预期薪资",
                detial: ''
            },
            {
                title: "文理比例",
                detial: ''
            },
            {
                title: "男女比例",
                detial: ''
            }
        ],
        dataSourceArray: [{
                dictValue: "0",
                dictLabel: "专业概况"
            },
            // {
            //     dictValue: "1",
            //     dictLabel: "开设院校"
            // },
            {
                dictValue: "1",
                dictLabel: "就业前景"
            }
        ],
        show:false,
        selectIndex:0, // 0 专业介绍 1课程要求 2就业方向 3具体职位
        tabSelectIndex:0, // 0 专业概况 1开设院校  2就业前景
        showprofessionList:[{title:'专业介绍',content:''},
                    {title:'培养目标',content:''},
                    {title:'培养要求',content:''},
                    {title:'名人学者',content:''}],
        showcourseList:[{title:'主干课程',content:''},
        {title:'学科要求',content:''},
        {title:'知识能力',content:''}],
        majorId:'',
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad(options) {
        this.setData({
            majorId:options.id,
            educational: options.educational,
            ['introList[' + 0 + '].detail']: options.educational == 1 ? "" : '高职专科',
            ['introList[' + 0 + '].title']: options.educational == 1 ? "授予学位" : '',
        })
        let openid = wx.getStorageSync('openId') || '';
        this._GetMajorDtl({
            id: options.id,
            openId:openid
        }, true)
    },

    // 收藏
  collectAction() {
    let openid = wx.getStorageSync('openId') || '';
    if (openid == '') {
        wx.navigateTo({
          url: '/pages/login/login',
        })
        return
    }
    if (this.data.model.isCollect == 0) {
        this.setData({
            'model.isCollect': 1
        })
        this._GetCollect({openId:openid,collectType:'2',majorId:this.data.majorId}, false)
    } else {
        this.setData({
            'model.isCollect': 0
        })
        this._GetCancelCollect({openId:openid,collectType:'2',majorId:this.data.majorId}, false)
    }
  },

    // tab 点击事件
    onChange(event) {
        console.log(event)
        this.setData({
            tabSelectIndex:event.detail.name
        })
    },

    // 专业介绍点击事件
    professionAction() {
        this.setData({
            show:true,
            selectIndex:0
        })
    },
    // 课程点击事件
    courseAction() {
        this.setData({
            show:true,
            selectIndex:1
        })
    },
    // 就业方向
    jobAction() {
        this.setData({
            show:true,
            selectIndex:2
        })
    },
    // 具体职位
    positionAction() {
        this.setData({
            show:true,
            selectIndex:3
        })
    },

    close() {
        this.setData({
            show:false,
        })
    },

      // 收藏
  _GetCollect:function(data,isLoading) {
    GetCollect(data, isLoading).then(res => {
      console.log(res)
      let code = res.code;
      if (code == 200) {
        // Toast("收藏成功")
      } else {
        // Toast(res.msg)
      }
    })
  },

       // 取消收藏
       _GetCancelCollect:function(data,isLoading) {
        GetCancelCollect(data, isLoading).then(res => {
          console.log(res)
          let code = res.code;
          if (code == 200) {
            // Toast("取消收藏成功")
          } else {
            // Toast(res.msg)
          }
        })
      },

  

    // 专业详情
    _GetMajorDtl: function (data, isLoading) {
        let that = this
        GetMajorDtl(data, isLoading).then(res => {
            console.log(res)
            let code = res.code;
            if (code == 200) {
                this.setData({
                    model: res.data,
                    ['introList[' + 0 + '].detail']: that.data.educational == 1 ? res.data.degree : '高职专科',
                    ['introList[' + 1 + '].detail']: res.data.rankAll == null ? '-' : res.data.rankAll,
                    ['introList[' + 2 + '].detail']: res.data.rankSalary == null ? '-' : res.data.rankSalary,
                    ['introList[' + 3 + '].detail']: (res.data.ratioArts == null ? '-' : res.data.ratioArts) + ':' + (res.data.ratioScience  == null ? '-' : res.data.ratioScience),
                    ['introList[' + 4 + '].detail']: (res.data.ratioMale  == null ? '-' : res.data.ratioMale) + ':' + (res.data.ratioFemale  == null ? '-' : res.data.ratioFemale),
                    ['showprofessionList[' + 0 + '].content']: res.data.mIntro,
                    ['showprofessionList[' + 1 + '].content']: res.data.mTarget,
                    ['showprofessionList[' + 2 + '].content']: res.data.mAsk,
                    ['showprofessionList[' + 3 + '].content']: res.data.mFamous,
                    ['showcourseList[' + 0 + '].content']: res.data.kcLesson,
                    ['showcourseList[' + 1 + '].content']: res.data.kcAsk,
                    ['showcourseList[' + 2 + '].content']: res.data.kcAbility,
                })

            } else {
                Toast(res.msg)
            }
        })
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady() {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow() {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide() {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload() {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh() {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom() {

    },

    onShareTimeline: function (){

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage() {

    }
})